//
//  MKDownBrowseCollectionViewCell.m
//  ManKeCartoon
//
//  Created by 邹功梁 on 15/10/28.
//  Copyright © 2015年 ManKe. All rights reserved.
//

#import "MKDownBrowseCollectionViewCell.h"
#import "MKBaseHeader.h"
@implementation MKDownBrowseCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        _scrollView.userInteractionEnabled = YES;
        _scrollView.panGestureRecognizer.delaysTouchesBegan = YES;
        _scrollView.contentSize = CGSizeZero;
        
        _scrollView.delegate = self;
        _scrollView.maximumZoomScale = 2;
        _scrollView.minimumZoomScale = 1;
        
        _tap_Image = [[UITapGestureRecognizer alloc] init];
        [_tap_Image setNumberOfTapsRequired:1];
        _tap_Image.delegate = self;
        [_scrollView addGestureRecognizer:_tap_Image];
        
        _photoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        
        [self.contentView addSubview:_scrollView];
        [_scrollView addSubview:_photoImageView];
    }
    return self;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if(touch.view != _scrollView){
        return NO;
    }else
        return YES;
}
- (void)setImageInfosImage:(UIImage *)image
{
    CGFloat width = image.size.width;
    CGFloat height = image.size.height;
    [_photoImageView setFrame:CGRectMake(0, (SCREEN_HEIGHT - SCREEN_WIDTH * height/ width) / 2, SCREEN_WIDTH, SCREEN_WIDTH * height/ width)];
    [_photoImageView setImage:image];
    // 设置ScrollView滚动范围 与图片尺寸一致
    _scrollView.contentSize = _photoImageView.frame.size;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return _photoImageView;
}
@end
